package SoftwareEngineering01.WordFrequence.Step2;

import SoftwareEngineering01.WordFrequence.Step1.Counting_01;
import SoftwareEngineering01.WordFrequence.readFile.Article;
import SoftwareEngineering01.WordFrequence.readFile.CompareWith;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class StopWord {
    public static void stopWord(String string) throws IOException{
        Map<String,Integer> map = Counting_01.getWordMap(string);
        String stopwordfile = "C:\\Users\\AA\\IdeaProjects\\repository\\SoftwareEngineering01\\stopword.txt";
        String stopwordstr = Article.article(new File(stopwordfile));
        String [] stopWords = stopwordstr.split("\\W+");
        for(String s : stopWords){
            map.remove((s));
        }
        List<Map.Entry<String,Integer>> list = new ArrayList<>();
        list.addAll(map.entrySet());
        CompareWith compareWith = new CompareWith();
        Collections.sort(list,compareWith);
        for(Map.Entry<String,Integer> item:list){
            System.out.println(item.getKey()+"出现的次数共有:"+item.getValue());
        }
    }
}
